﻿package mortal.game.view.arena.view
{
    import Message.Public.*;
    import com.gengine.utils.*;
    import com.mui.controls.*;
    import com.mui.utils.*;
    import extend.language.*;
    import flash.events.*;
    import mortal.common.global.*;
    import mortal.component.window.*;
    import mortal.game.cache.*;
    import mortal.game.control.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.scene3D.map3D.util.*;
    import mortal.game.view.arena.data.*;
    import mortal.game.view.arena.util.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.display.*;
    import mortal.game.view.shopMall.data.*;
    import mortal.mvc.core.*;
    import mortal.mvc.interfaces.*;

    public class ArenaResultWinNew extends ResultBaseWindow
    {
        private var _titleIcon:GImageBitmap;
        private var _roleName:GTextFiled;
        private var _roleInfo:GTextFiled;
        private var _tipInfo:GImageBitmap;
        private var _gainPoint:GTextFiled;
        private var _gainGold:GTextFiled;
        private var _totalPoint:BitmapNumberText;
        private var _tips:GTextFiled;
        private var _goldShopLink:GButton;
        private var _lookRankLink:GButton;
        private var _headSpr:GSprite;
        private static var _instance:ArenaResultWinNew;

        public function ArenaResultWinNew(param1:ILayer = null)
        {
            super(param1);
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._titleIcon = UIFactory.gImageBitmap(ImagesConst.ResultWinSuccess, 327 - 98 + 3, 37 - 78, this);
            this.pushUIToDisposeVec(UIFactory.bg(254 - 20, 87 - 3, 231, 100, this));
            this._headSpr = UICompomentPool.getUICompoment(GSprite);
            this._headSpr.y = 53 - 8;
            this.addChild(this._headSpr);
            this._roleName = UIFactory.gTextField("", 0, 0, 100, 20, this._headSpr);
            this._roleName.htmlText = HTMLUtil.addLink("", GlobalStyle.colorLv);
            this._roleName.configEventListener(MouseEvent.CLICK, this.onLinkClickHandler);
            this._roleName.configEventListener(MouseEvent.MOUSE_OVER, this.onOverHandler);
            this._roleName.configEventListener(MouseEvent.MOUSE_OUT, this.onOutHandler);
            this._roleInfo = UIFactory.gTextField("", this._roleName.x + this._roleName.textWidth + 2, 0, 153 + 17, 20, this._headSpr);
            this._tipInfo = UIFactory.gImageBitmap(ImagesConst.ArenaText_SuccFeat, this._roleInfo.x + this._roleInfo.textWidth + 3, 0, this._headSpr);
            this._headSpr.x = (this.width - 87 - this._headSpr.width) / 2;
            this.pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.ArenaResultTextBg, 254 - 20 + 5, 87 - 2 + 1, this));
            this.pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.ArenaResultText, 254 + 67, 90 - 3, this));
            this.pushUIToDisposeVec(UIFactory.gTextField(Language.getString(40827), 254 - 20 + 5 + 59, 86 + 43 - 9, 85, 25, this, GlobalStyle.textFormatPutong.setSize(14)));
            this.pushUIToDisposeVec(UIFactory.gTextField(Language.getString(40828), 254 - 20 + 5 + 59, 86 + 43 + 23 - 9, 85, 25, this, GlobalStyle.textFormatPutong.setSize(14)));
            this._gainPoint = UIFactory.gTextField("", 254 - 20 + 5 + 130, 86 + 43 - 9, 63, 25, this, GlobalStyle.textFormatHuang2.setSize(14));
            this._gainGold = UIFactory.gTextField("", 254 - 20 + 5 + 130 + 10, 86 + 43 + 23 - 9, 63, 25, this, GlobalStyle.textFormatHuang2.setSize(14));
            this.pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.ArenaText_TotalPoint, 254 - 20 + 62 - 17, 84 + 110, this));
            this._totalPoint = UIFactory.bitmapNumberText(254 - 20 + 126 - 17, 84 + 110 + 4, "WizardNum.png", 13, 17, -1, this);
            this._totalPoint.text = "";
            this._tips = UIFactory.gTextField("", 254 - 20 - 45, 84 + 179, 200, 20, this);
            this._tips.htmlText = HTMLUtil.addColor(Language.getString(40829), GlobalStyle.colorLv) + HTMLUtil.addColor(Language.getString(40830), GlobalStyle.colorHuang2);
            this._goldShopLink = UIFactory.gButton(Language.getString(40831), 254 - 20 + 165, 84 + 179, 65, 20, this, "GreenLinkButton");
            this._lookRankLink = UIFactory.gButton(Language.getString(40832), 254 - 20 + 235, 84 + 179, 75, 20, this, "GreenLinkButton");
            this._goldShopLink.configEventListener(MouseEvent.CLICK, this.onClickHandler);
            this._lookRankLink.configEventListener(MouseEvent.CLICK, this.onClickHandler);
            this.updateSize();
            return;
        }// end function

        public function updateArenaResult() : void
        {
            var _loc_3:ArenaFightDetailData = null;
            var _loc_1:* = Cache.instance.arena.getArenaResultData(ArenaConst.Type_ArenaResult_Self);
            var _loc_2:* = Cache.instance.arena.getArenaResultData(ArenaConst.Type_ArenaResult_Other);
            if (_loc_1 && _loc_2)
            {
                if (_loc_2.entityId.id == Cache.instance.role.entityInfo.entityId.id)
                {
                    _loc_3 = _loc_1;
                    _loc_1 = _loc_2;
                    _loc_2 = _loc_3;
                }
                if (_loc_1.isFail)
                {
                    this._titleIcon.imgUrl = ImagesConst.ResultWinFail;
                    this._tipInfo.imgUrl = ImagesConst.ArenaText_BeFeat;
                    this._tipInfo.x = 0;
                    this._roleName.htmlText = HTMLUtil.addLink(_loc_2.roleName, GlobalStyle.colorLv);
                    this._roleName.x = this._tipInfo.x + 38;
                    this._roleInfo.text = Language.getStringByParam(40833, _loc_2.level, _loc_2.careerName, _loc_2.combat);
                    this._roleInfo.x = this._roleName.x + this._roleName.textWidth + 2;
                    this._headSpr.x = (this.width - 47 - this._headSpr.width) / 2;
                }
                else
                {
                    this._titleIcon.imgUrl = ImagesConst.ResultWinSuccess;
                    this._roleName.htmlText = HTMLUtil.addLink(_loc_2.roleName, GlobalStyle.colorLv);
                    this._roleName.x = 0;
                    this._roleInfo.text = Language.getStringByParam(40833, _loc_2.level, _loc_2.careerName, _loc_2.combat);
                    this._roleInfo.x = this._roleName.x + this._roleName.textWidth + 2;
                    this._tipInfo.imgUrl = ImagesConst.ArenaText_SuccFeat;
                    this._tipInfo.x = this._roleInfo.x + this._roleInfo.textWidth + 3;
                    this._headSpr.x = (this.width - 87 - this._headSpr.width) / 2;
                }
                if (_loc_1.gainPoint > 0)
                {
                    this._gainPoint.htmlText = HTMLUtil.addColor("+" + _loc_1.gainPoint, GlobalStyle.colorLv);
                }
                else
                {
                    this._gainPoint.htmlText = HTMLUtil.addColor("" + _loc_1.gainPoint, GlobalStyle.colorHong);
                }
                if (_loc_1.gainGoldNote > 0)
                {
                    this._gainGold.htmlText = HTMLUtil.addColor("+" + _loc_1.gainGoldNote, GlobalStyle.colorHuang2);
                }
                else
                {
                    this._gainGold.htmlText = HTMLUtil.addColor("" + _loc_1.gainGoldNote, GlobalStyle.colorHong);
                }
                this._totalPoint.text = "" + _loc_1.totalPoint;
            }
            return;
        }// end function

        override protected function updateSize() : void
        {
            super.updateSize();
            if (_typeBg)
            {
                _typeBg.x = _typeBg.x - 11;
            }
            if (_enterBtn)
            {
                _enterBtn.x = _enterBtn.x - 10;
            }
            if (_enterBtn)
            {
                _enterBtn.y = _enterBtn.y - 18;
            }
            return;
        }// end function

        override protected function addContentBg() : void
        {
            return;
        }// end function

        override protected function setContentBgSize(param1:int, param2:int) : void
        {
            return;
        }// end function

        private function onLinkClickHandler(event:Event) : void
        {
            var _loc_5:SEntityId = null;
            var _loc_2:* = ELookUpType._ELookUpTypePlayer;
            var _loc_3:* = Cache.instance.arena.getArenaResultData(ArenaConst.Type_ArenaResult_Self);
            var _loc_4:* = Cache.instance.arena.getArenaResultData(ArenaConst.Type_ArenaResult_Other);
            if (_loc_3 && _loc_4)
            {
                if (_loc_4.entityId.id == Cache.instance.role.entityInfo.entityId.id)
                {
                    _loc_5 = _loc_3.entityId;
                }
                else
                {
                    _loc_5 = _loc_4.entityId;
                }
                Dispatcher.dispatchEvent(new DataEvent(EventName.LookPlayerInfo, _loc_5));
            }
            return;
        }// end function

        private function onClickHandler(event:MouseEvent) : void
        {
            var _loc_2:int = 0;
            if (event.target == this._goldShopLink)
            {
                _loc_2 = ArenaUtil.getArenaMoneyByLevel(ArenaController.ArenaLevel).shopIndex;
                Dispatcher.dispatchEvent(new DataEvent(EventName.ShopMallChangeTabIndex, [ShopUtil.ShopTabArena1v1, _loc_2]));
            }
            if (event.target == this._lookRankLink)
            {
                GameController.ranking.view.show();
            }
            return;
        }// end function

        private function onOverHandler(event:MouseEvent) : void
        {
            CursorManager.showCursor(CursorManager.BUTTON);
            return;
        }// end function

        private function onOutHandler(event:MouseEvent) : void
        {
            CursorManager.hideFromButton();
            return;
        }// end function

        override protected function enterBtnClickHandler(event:MouseEvent) : void
        {
            if (GameMapUtil.curMapState.isArenaCopy)
            {
                GameProxy.copy.leaveCopy();
            }
            hide();
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl();
            this._titleIcon.dispose();
            this._titleIcon = null;
            this._roleName.dispose();
            this._roleName = null;
            this._roleInfo.dispose();
            this._roleInfo = null;
            this._tipInfo.dispose();
            this._tipInfo = null;
            this._gainPoint.dispose();
            this._gainPoint = null;
            this._gainGold.dispose();
            this._gainGold = null;
            this._totalPoint.dispose();
            this._totalPoint = null;
            this._tips.dispose();
            this._tips = null;
            this._goldShopLink.dispose();
            this._goldShopLink = null;
            this._lookRankLink.dispose();
            this._lookRankLink = null;
            this._headSpr.dispose();
            this._headSpr = null;
            return;
        }// end function

        public static function get instance() : ArenaResultWinNew
        {
            if (_instance == null)
            {
                _instance = new ArenaResultWinNew;
            }
            return _instance;
        }// end function

        public static function hasInstance() : Boolean
        {
            return _instance != null;
        }// end function

        public static function isViewShow() : Boolean
        {
            return _instance && !_instance.isHide;
        }// end function

    }
}
